package com.avidys.gwt.ext;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.user.client.Element;

public class TestExtJs extends LayoutContainer {
	
	protected void onRender(Element parent, int index) {
		 SelectionListener<ButtonEvent> l = new SelectionListener<ButtonEvent>() {
		      public void componentSelected(ButtonEvent ce) {
		        Info.display("Click", ce.getButton().getText() + " clicked");
		      }
		    };		    
	    super.onRender(parent, index);
	    setLayout(new FlowLayout(10));

	    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

	    ColumnConfig column = new ColumnConfig();
	    column.setId("Step");
	    column.setHeader("Step");
	    column.setWidth(50);
	    configs.add(column);

	    //column = new ColumnConfig("Date", "Date", 50);
	    //column.setAlignment(HorizontalAlignment.CENTER);
	    //column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
	    //configs.add(column);

	    column = new ColumnConfig();
	    column.setId("Function");
	    column.setHeader("Function");
	    column.setWidth(100);
	    configs.add(column);

	    column = new ColumnConfig();
	    column.setId("Result");
	    column.setHeader("Result");
	    //column.setAlignment(HorizontalAlignment.RIGHT);
	    column.setWidth(400);
	    configs.add(column);

	    //column = new ColumnConfig("SID", "SID", 100);
	    //column.setAlignment(HorizontalAlignment.RIGHT);
	    //configs.add(column);

	    //column = new ColumnConfig(" ", " ", 20);
	    //column.setAlignment(HorizontalAlignment.CENTER);
	    //configs.add(column);
	    
	    ColumnModel cm = new ColumnModel(configs);

	    ContentPanel cp = new ContentPanel();
		cp.setBodyBorder(false);
		cp.setHeading("Widget Renderer Grid");
		cp.setButtonAlign(HorizontalAlignment.CENTER);
		cp.setLayout(new FitLayout());
		cp.setSize(800, 300);

		
	    class Kid extends BaseModelData {
	        public Kid(String name, String age) {
	          set("Step", name);
	          set("Function", age);
	          set("Result","www");
	        }
	      }

	      List<Kid> kids = new ArrayList<Kid>();
	      kids.add(new Kid("Alec", "123"));
	      kids.add(new Kid("Lia", "2dd"));
	      kids.add(new Kid("Andrew", "1"));

	    final ListStore store = new ListStore();
	    store.add(kids);
	    
	    Grid grid = new Grid(store, cm);
	    grid.setStyleAttribute("borderTop", "none");
	    grid.setAutoExpandColumn("name");
	    grid.setBorders(true);

//		TestGrid grid = new TestGrid(Steps);
//		grid.setBorderWidth(1);

		cp.add(grid);

		add(cp);
	}
}
